﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace Xpom_Xpum__Code_Generator.Core
{
    class ManifestClass
    {
        public int manifest_version
        {
            get
            {
                return Convert.ToInt32(JObjectCore["manifest_version"].ToString());
            }
            set
            {
                if (Convert.ToInt32(JObjectCore["manifest_version"].ToString()) != value)
                    JObjectCore["manifest_version"] = value;
            }
        }

        public string name
        {
            get
            {
                return JObjectCore["name"].ToString();
            }
            set
            {
                if (JObjectCore["name"].ToString() != value)
                    JObjectCore["name"] = value;
            }
        }

        public string version
        {
            get
            {
                return JObjectCore["version"].ToString();
            }
            set
            {
                if (JObjectCore["version"].ToString() != value)
                    JObjectCore["version"] = value;
            }
        }

        public JObject JObjectCore;

        public static ManifestClass Parse(string path)
        {
            var mc = new ManifestClass();
            mc.JObjectCore = JObject.Parse(path);
            mc.name = mc.JObjectCore["name"].ToString();
            return mc;
        }

        public void Save(string path)
        {
            File.WriteAllText(path, JObjectCore.ToString());
        }
    }
}
